<?php

/**
 * 开放接口
 */
class Api_WeConsult extends PhalApi_Api
{
    public function getRules()
    {
        return array(
            'insertComment' => [
                'fid' => ['name' => 'fid', 'type' => 'int', 'require' => true,'desc' => '帖子或视频或快讯id'],
                'pid' => ['name' => 'fid', 'type' => 'int', 'require' => true,'desc' => '被评论人'],
                'type' => ['name' => 'type', 'type' => 'int', 'require' => true,'desc' => '咨询类型 1咨询 2视频 3快讯'],
                'comment' => ['name' => 'comment', 'type' => 'string', 'require' => true, 'min' => 1,'max' => 200, 'desc' => '评论内容'],
            ],
            'deleteComment' => [
                'id' => ['name' => 'id', 'type' => 'int', 'require' => true, 'desc' => '评论id'],
            ],
            'insertCommentLike' => [
//                'userId' => ['name' => 'userId', 'type' => 'int', 'require' => true, 'desc' => '用户id'],
                'fid' => ['name' => 'fid', 'type' => 'int', 'require' => true,'desc' => '评论id'],
            ],
            'deleteCommentLike' => [
                'fid' => ['name' => 'fid', 'type' => 'int', 'require' => true, 'desc' => '评论id'],
            ],
//            'bindClassPage' =>[
//            ],
//            'bindClass' =>[
//                'consultClassId' => ['name' => 'consultClassId', 'type' => 'string', 'require' => true,'desc' => '用户板块'],
//            ],
            'insertConsult' => [
                'consultName' => ['name' => 'consultName', 'type' => 'string', 'min' => 1,'max' => 50, 'require' => true, 'desc' => '咨询名称'],
                'consultImg' => ['name' => 'consultImg', 'type' => 'string',  'min' => 1,'max' => 150,'require' => false, 'desc' => '咨询图片链接'],
                'video' => ['name' => 'video', 'type' => 'string',  'min' => 1,'max' => 150,'require' => false, 'desc' => '视频链接'],
                'consultDetail' => ['name' => 'consultDetail', 'type' => 'string','require' => true, 'desc' => '咨询内容'],
//                'top' => ['name' => 'top', 'type' => 'int','require' => true, 'desc' => '置顶顺序 默认1'],
                'classId' => ['name' => 'classId', 'type' => 'int', 'require' => true, 'desc' => '分类id'],
                'authorId' => ['name' => 'authorId', 'type' => 'int', 'require' => true, 'desc' => '作者id'],
                'recommendId' => ['name' => 'recommendId', 'type' => 'int','require' => false, 'desc' => '推荐模板id'],
//                'hot'=>['name'=>'hot','type'=>'int', 'require' => false,'desc'=>'是否热门 0不是 1是']
            ],
            'selfConsult' => [
                'page' => ['name' => 'page', 'type' => 'int', 'require' => true,'desc' => '页码第一页传1'],
            ],

        );
    }

    /**
     * 发送评论
     * @return int code 1操作成功
     * @return string context 问题详细描述
     * @return array data url
     * @desc wjp 2017-12-25
     */
    public function insertComment(){
        $data = $this -> allParams();
        $domain = new Domain_WeConsult();
        $rolerCode = DI()->Ruler->Roler($data['comment']);

        if($rolerCode == -100)
            return DI()->ResCode->get("WE.rulerError");
        $data['userId'] = DI()->user['id'];
        $code = $domain -> insertComment($data);
        if($code != null)
            return DI()->ResCode->get("WE.Success");
        return DI()->ResCode->get("WE.Error");
    }

    /**
     * 删除评论
     * @return int code 1操作成功
     * @return string context 问题详细描述
     * @return array data url
     * @desc wjp 2017-12-25
     */
    public function deleteComment(){
        $data = $this -> allParams();
        $domain = new Domain_WeConsult();
        $code = $domain -> deleteComment($data);
        if($code > 0)
            return DI()->ResCode->get("WE.Success");
        return DI()->ResCode->get("WE.Error");
    }

    /**
     * 评论点赞
     * @return int code 1操作成功
     * @return string context 问题详细描述
     * @return array data url
     * @desc wjp 2017-12-25
     */
    public function insertCommentLike(){
        $data = $this -> allParams();
        $domain = new Domain_WeConsult();
        $data['userId'] = DI()->user['id'];
        $data['pid'] = 0;
        $data['type'] = 1;
//        print_r($data);exit;
        $code = $domain -> insertCommentLike($data);
        if($code > 0)
            return DI()->ResCode->get("WE.Success");
        return DI()->ResCode->get("WE.Error");
    }

    /**
     * 删除评论点赞
     * @return int code 1操作成功
     * @return string context 问题详细描述
     * @return array data url
     * @desc wjp 2017-12-25
     */
    public function deleteCommentLike(){
        $data = $this -> allParams();
        $domain = new Domain_WeConsult();
        $code = $domain -> deleteCommentLike($data);
        if($code > 0)
            return DI()->ResCode->get("WE.Success");
        return DI()->ResCode->get("WE.Error");
    }

    /**
     * 新建咨询
     * @desc wjp 2017-1-4
     * @throws PhalApi_Exception_InternalServerError
     */
    public function insertConsult(){
        $allParams = $this -> allParams();
        $domain = new Domain_WeConsult();
        $userInfo = $domain -> insertConsult($allParams);
        $ret = DI()->ResCode->get("WE.Success");
        $ret['data'] = $userInfo;
        return $userInfo;
    }

    /**
     * 自己的帖子
     * @desc wjp 2017-1-4
     * @throws PhalApi_Exception_InternalServerError
     */
    public function selfConsult(){
        $allParams = $this -> allParams();
        $domain = new Domain_WeConsult();
        $allParams['authorId'] = DI() -> user['id'];
        $list = $domain->ConsultList($allParams);
        $res = DI()->ResCode->get("WE.Success");
        $res['data'] = $list;
        return $res;
    }
}